<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
  	<base href="<%=basePath%>"> 
<TITLE>DAWU WebServer Home</TITLE>
<LINK REL="stylesheet" HREF="css/dwdoor.css" TYPE="text/css">
<link rel="stylesheet" type="text/css" href="css/index.css">
<link rel="stylesheet" type="text/css" href="css/custom_select.css">
<link rel="stylesheet" type="text/css" href="css/jquery-ui.css" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery.csf.js"></script>
<script type="text/javascript" src="js/jquery-cookie.js"></script>
<script type="text/javascript" src="lang/b28n.js"></script>
<script type="text/javascript" src="js/func.js"></script>
<script type="text/javascript" src="js/base64.min.js"></script>
<script type="text/javascript">
</script>
</HEAD>

<BODY onLoad="">
<div class="contain">

<!-- ================= SNUM/WEBADD/CARMEADD Settings ================= -->
<div class="sec" id="div_date">
<div class="title">设备参数设置</div>
<form method=post id="dwGateSetting" name="dwGateSetting" action="" >
    <div class="content">
        <div>
            <ul>
                <li class="necessary  spec">
                    <span class="name">设备号</span>
                    <span class="conn ">
						<select onchange="settab(this[selectedIndex].value,'');" name="controlernum" id="controlerNum">
                        
						</select>
                    </span>
                </li>
				<li class="necessary">
                    <span class="name">门号</span>
                    <select onchange="settab('',this[selectedIndex].value);" name="gatenum" id="GateNum">						
						<option value="all">全部</option>
						<option value="0">一号门进口</option>
                        <option value="1">一号门出口</option>
                        <option value="2">二号门进口</option>
                        <option value="3">二号门出口</option>						
                    </select>
                </li>
                
                <li class="necessary">
                    <span class="name">门名</span>
                     <input class="text" type="text" size="17" name="gatename" maxlength=17  value="大门"/>
                </li>
                <li class="necessary">
                    <span class="name">区域</span>
                     <input class="text" type="text" size="17"  value="总部" name="region" maxlength=17 />
                </li>
                <li class="necessary">
                    <span class="name">开门方式</span>
                    <select name="controlmethod" id="g3">
                       <option value="card">刷卡</option>
                       <option value="password">密码</option>
                       <option value="card&password">卡加密码</option>
					   <option value="cardorpass">卡或密码</option>
					   <option value="card">未设置，默认 刷卡</option>
                    </select>
                </li>
                <li class="necessary">
                    <span class="name">开门延时</span>
                     <input class="text" type="text" size="17"  name="delayopentime" maxlength=2 value="0"/>秒
                </li>
                <li class="necessary">
                    <span class="name">关门延时</span>
                     <input class="text" type="text" size="17"  name="delayclosetime" maxlength=2 value="0" />秒
                </li>
                <li class="necessary">
                    <span class="name">门磁</span>
                   <select name="sensorstat" id="g4">
                       <option value="NG">无</option>
                       <option value="OK">有</option>
					   <option value="NG">未设置，默认 无</option>
                    </select>
                </li>
              
                <li class="necessary">
                    <span class="name">是否考勤</span>
                    <select name="attendancecheck" id="g6">
                       <option value="yes">是</option>
                       <option value="no">否</option>
					   <option value="yes">未设置，默认 是</option>
                    </select>
                </li>
				
				<li class="necessary">
                    <span class="name">反潜回</span>
                    <select name="antipassback" id="g7">
                       <option value="no">无</option>
                       <option value="yes">有</option>
					   <option value="no">未设置，默认 无</option>
                    </select>
                </li>				
            </ul>
        </div>
    </div>
</form>
<div class="btn-part">
    <div class="button-container">
    <!--<button id="manApply" class="button-button btn-pre" type="button"  type=submit   onclick='dwGatesubmit();'>提交</button>-->
    <!--<button id="manCancel" class="button-button btn-next" type="button"  type=reset   >取消</button>-->              
    <button id="manDownLoad" class="button-button btn-pre" type="button"  type=submit   onclick='dwGateSettingCheck();'>下发</button>
	</div>
</div>
</div>

</div>
</BODY>
<script type="text/javascript">
function dwGateSettingCheck()
{
	var delayopentime=document.dwGateSetting.delayopentime.value;
    var delayclosetime=document.dwGateSetting.delayclosetime.value;
    if(delayopentime=="")
    {
        if($.cookie('language') === "en")
		    alert( "Please input delayopentime." );
		if($.cookie('language') != "en")
		    alert( "请输入开门延时。" );
        document.dwGateSetting.delayopentime.focus();
        return false;
    }
	if(delayclosetime=="")
    {
        if($.cookie('language') === "en")
		    alert( "Please input delayclosetime." );
		if($.cookie('language') != "en")
		    alert( "请输入关门延时。" );
        document.dwGateSetting.delayclosetime.focus();
        return false;
    }
	if(!isAllNum(delayopentime))
    {
        if($.cookie('language') === "en")
		    alert( "Only mumber can be input." );
		if($.cookie('language') != "en")
		    alert( "开门延时只能是数字，请重新输入。delayopentime："+delayopentime );
        document.dwGateSetting.delayopentime.focus();
        return false;
    }
	if(!isAllNum(delayclosetime))
    {
        if($.cookie('language') === "en")
		    alert( "Only mumber can be input." );
		if($.cookie('language') != "en")
		    alert( "关门延时只能是数字，请重新输入。" );
        document.dwGateSetting.delayclosetime.focus();
        return false;
    }
	var gatename=document.dwGateSetting.gatename.value;
	var region=document.dwGateSetting.region.value;
	if(gatename=="")
    {
        if($.cookie('language') === "en")
		    alert( "Please input gatname." );
		if($.cookie('language') != "en")
		    alert( "请输入开门门名。" );
        document.dwGateSetting.gatename.focus();
        return false;
    }
	if(region=="")
    {
        if($.cookie('language') === "en")
		    alert( "Please input region." );
		if($.cookie('language') != "en")
		    alert( "请输入区域。" );
        document.dwGateSetting.region.focus();
        return false;
    }
	
	if(isRealLength(gatename)>12)
    {
        alert('门名太长，请重新输入。');
        document.dwGateSetting.gatename.focus();
        return false;
    }
	if(isRealLength(region)>12)
    {
        alert('区域名字太长，请重新输入。');
        document.dwGateSetting.region.focus();
        return false;
    }
//	document.getElementById("controler_Num").value = document.getElementById("controlerNum").value;	
	var ControlerNum=document.dwGateSetting.controlernum.value;
	var gatenum=document.dwGateSetting.gatenum.value;
	var controlmethod=document.dwGateSetting.controlmethod.value;
	var sensorstat=document.dwGateSetting.sensorstat.value;
	var attendancecheck=document.dwGateSetting.attendancecheck.value;
	var antipassback=document.dwGateSetting.antipassback.value;
	var downArr='{"action":"dwdowngate","ControlerNum":"'+ControlerNum+'","gatenum":"'+gatenum+'","gatename":"'+gatename+'","region":"'+region+'","delayopentime":"'+delayopentime+'","delayclosetime":"'+delayclosetime+'","controlmethod":"'+ controlmethod+'","sensorstat":"'+sensorstat+'","attendancecheck":"'+attendancecheck+'","antipassback":"'+antipassback+'"}';
    dwDownLoad(downArr);
	return true; 
}
/*
function dwGatesubmit()
{
    if(dwGateSettingCheck()) document.getElementById("dwGateSetting").submit();
}
*/
function settab(controlernumopvalue,gatenumopvalue)
{
	if(controlernumopvalue==="")
    {	
	    var ControlerNum=document.dwGateSetting.controlernum.value;
	}else
	{
	    var ControlerNum=controlernumopvalue;
	}
	if(gatenumopvalue==="")
	{
	    var gatenum=document.dwGateSetting.gatenum.value;
	}else
	{
	    var gatenum=gatenumopvalue;
	}	
	var datastr='{"action":"dwgetgatetab","ControlerNum":"'+ControlerNum+'","gatenum":"'+gatenum+'"}';
//    alert(datastr);
	$.ajax({
        url: "/dw/Dwbrowser",
        type: "POST",
        timeout: 180000,
        data: datastr,
        dataType: "text",
//			async: true,
        error: function()
		{
		    $('#massage_text').text('网络错误。'); 
            return false;
        },
        complete: function()
		{              
            if (status === 'timeout')
			{
                $('#massage_text').text('超时。');
				this.abort();
            }
        },
        success: function(deReturn)
		{            
			var gatetab =jQuery.parseJSON(deReturn);            
			if(gatetab['s1_0']==""||gatetab['s1_0']=="null"||gatetab['s1_0']==null)
			{
				document.dwGateSetting.gatename.value = "未设置";
			}else if(gatetab['s1_0']!=="")
			{
				document.dwGateSetting.gatename.value = gatetab['s1_0'];
//				alert("gatename:"+gatetab['s1_0']+__LINE__);
			}
//			else
//			{
//				alert("gatename:"+gatetab['s1_0']+__LINE__);
//			}
			if(gatetab['s1_1']==""||gatetab['s1_1']=="null"||gatetab['s1_1']==null)
			{
				document.dwGateSetting.region.value = "未设置";
			}else if(gatetab['s1_1']!=="") 
			{
				document.dwGateSetting.region.value = gatetab['s1_1'];
			}
			if(gatetab['s1_2']==""||gatetab['s1_2']=="null"||gatetab['s1_2']==null)
			{
				 $("#g3").get(0).selectedIndex=4;
			}
/*			else if(gatetab['s1_2']!=="")
			{
				document.dwGateSetting.controlmethod.value = gatetab['s1_2'];
			}*/
			if(gatetab['s1_2']=="card") $("#g3 option[text='card']").attr("selected", true);
			if(gatetab['s1_2']=="password") $("#g3 option[text='password']").attr("selected", true);
			if(gatetab['s1_2']=="card&password") $("#g3").get(0).selectedIndex=2;
			if(gatetab['s1_2']=="cardorpass") $("#g3 option[text='cardorpass']").attr("selected", true);			
			if(gatetab['s1_3']==""||gatetab['s1_3']=="null"||gatetab['s1_3']==null)
			{
				document.dwGateSetting.delayopentime.value = "未设置";
			}else if(gatetab['s1_3']!=="")
			{
				document.dwGateSetting.delayopentime.value = gatetab['s1_3'];
			}			
			if(gatetab['s1_4']==""||gatetab['s1_4']=="null"||gatetab['s1_4']==null)
			{
				document.dwGateSetting.delayclosetime.value = "未设置";
			}else if(gatetab['s1_4']!=="")
			{
				document.dwGateSetting.delayclosetime.value = gatetab['s1_4'];
			}
			if(gatetab['s1_5']==""||gatetab['s1_5']=="null"||gatetab['s1_5']==null) $("#g4").get(0).selectedIndex=2;
//			if(gatetab['s1_2']=="NG") $("#g4").get(0).selectedIndex=0;
//			if(gatetab['s1_2']=="OK") $("#g4").get(0).selectedIndex=1;
			if(gatetab['s1_5']=="NG") $("#g4").get(0).selectedIndex=0;
			if(gatetab['s1_5']=="OK") $("#g4").get(0).selectedIndex=1;
			if(gatetab['s1_6']==""||gatetab['s1_6']=="null"||gatetab['s1_6']==null) $("#g6").get(0).selectedIndex=2;
//			if(gatetab['s1_2']=="yes") $("#g6").get(0).selectedIndex=0;
//			if(gatetab['s1_2']=="no") $("#g6").get(0).selectedIndex=1;
			if(gatetab['s1_6']=="yes") $("#g6").get(0).selectedIndex=0;
			if(gatetab['s1_6']=="no") $("#g6").get(0).selectedIndex=1;
//			if(gatetab['s1_7']!=="") document.dwGateSetting.antipassback.value = gatetab['s1_7'];
			if(gatetab['s1_7']==""||gatetab['s1_7']=="null"||gatetab['s1_7']==null) $("#g7").get(0).selectedIndex=2;
//		    if(gatetab['s1_2']=="yes") $("#g7").get(0).selectedIndex=1;
//			if(gatetab['s1_2']=="no") $("#g7").get(0).selectedIndex=0;
			if(gatetab['s1_7']=="yes") $("#g7").get(0).selectedIndex=1;
			if(gatetab['s1_7']=="no") $("#g7").get(0).selectedIndex=0;
		}
    });	
}

function dwDownLoad(downArr)
{
//    if(!dwGateSettingCheck()) return false;
//	dwGatesubmit();
//	var retnresult = dwGatesubmit();
//	if(retnresult!=='success') return false;
//	var ControlerNum=document.dwGateSetting.controlernum.value;
//	var gatenum=document.dwGateSetting.gatenum.value;
//	var downArr='{"action":"down","ControlerNum":"'+ControlerNum+'","gatenum":"'+gatenum+'"}';
	$.ajax({
        url: "/dw/Dwbrowser",
        type: "POST",
        timeout: 180000,
        data: downArr,
        dataType: "text",
//          async: true,
        error: function()
        {
            $('#massage_text').text('网络错误。'); 
            return false;
        },
        complete: function()
        {              
            if (status === 'timeout')
            {
                $('#massage_text').text('超时。');
                this.abort();
            }
        },
        success: function(deReturn)
        {
		    alert("deReturn:"+deReturn);
			if(deReturn==="success")
			{
			    alert('下发完成。');
			    self.setTimeout(window.location.href='/dw/door/gatesetting.jsp',6000);
			}else if(deReturn==="fail")
			{
			    alert('下发失败。');
//			    self.setTimeout(window.location.href='/door/gatesetting.php',6000);
			}else if(deReturn==="fail01")
			{
			    alert('输入为空或太长。');
//			    self.setTimeout(window.location.href='/door/gatesetting.php',6000);
			}
		}
	});	
}

function ajaxGetControlerNum()
{
    $.ajax({
        url: "/dw/Dwbrowser",
        type: "POST",
        timeout: 180000,
        data: "dwgetControlerNum",
        dataType: "text",
        error: function()
		{
		    $('#massage_text').text('网络错误。'); 
            return false;
        },
        complete: function()
		{              
            if (status === 'timeout')
			{
                $('#massage_text').text('超时。');
				this.abort();
            }
        },
        success: function(deReturn)
		{
            var DcSelection_element = document.getElementById("controlerNum");
            var dcSelectiontab =jQuery.parseJSON(deReturn); 
			for(var i=1;i<=dcSelectiontab.nrows;i++)
            {
				DcSelection_element.options[i-1] = new Option(dcSelectiontab['s'+i+'_0'], dcSelectiontab['s'+i+'_0']);
			}
			settab(dcSelectiontab['s1_0'],'');	
	    }
    });	
}

function initValue() 
{	
	ajaxGetControlerNum();
}

$(document).ready(function()
{
   initValue();
//   $('#GateNum').customSelectForm({index:2});
//   $('#g4').customSelectForm({index:3});
//   $('#g5').customSelectForm({index:4});
//   $('#g6').customSelectForm({index:5});
//   $('#g3').customSelectForm({index:6});
//   $('#g7').customSelectForm({index:7});
//   $('#controlerNum').customSelectForm({index:1});
});   

$(function()
{
	if($.cookie('logon') === "null" || !$.cookie('logon'))
	{
		top.window.location.pathname = '/dw/index.jsp';
	}
		
  	function checkCookie()
	{
	  	var a = $.cookie('logon') === "null" || !$.cookie('logon');
	  	if(a)
		{
	  		top.window.location.pathname = '/dw/index.jsp';
	  	}else
		{
		    var date = new Date();
		    date.setTime(date.getTime() + (60 * 60 * 1000));
		    $.cookie('logon',true,{expires: date});		 
		}
	}
});
</script>
</HTML>

